import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../login/widget/content_text_field_widget.dart';
import 'user_config.dart';

class UserInfoEditInfoNickPage extends StatefulWidget {
  const UserInfoEditInfoNickPage({super.key, required this.nickname});
  final Nickname nickname;
  @override
  State<UserInfoEditInfoNickPage> createState() => _UserInfoEditInfoNickPageState();
}

class _UserInfoEditInfoNickPageState extends State<UserInfoEditInfoNickPage> {
  String nick = ''; //昵称

  void fetchSubmitEditInfo() {
    HttpProvider.post(
      '/user/subEditInfo',
      params: {
        'colname': 'nickname',
        'colvalue': nick,
      },
      explain: '用户提交编辑信息',
      success: (result) {
        Get.back(result: nick);
      },
      failure: (result) {
        Toast.showText(result.message);
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    nick = widget.nickname.value ?? '';
    return Scaffold(
      appBar: BrnAppBar(
        title: '个人资料',
        backgroundColor: Colors.white,
        actions: [
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 8),
            child: BrnSmallMainButton(
              width: 50,
              title: "保存",
              bgColor: const Color(0xFF25D4D0),
              themeData: BrnButtonConfig(smallButtonHeight: 15.h, smallButtonFontSize: 12, smallButtonRadius: 13.r),
              insertPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 1),
              onTap: () {
                fetchSubmitEditInfo();
              },
            ),
          )
        ],
      ),
      backgroundColor: Colors.white,
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Column(
          // mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(height: 10.h),
            ContentTextFieldWidget(
              hintText: '给自己取个昵称吧~',
              text: nick,
              number: true,
              maxLength: widget.nickname.maxnum,
              onChanged: (value) {
                nick = value;
              },
              onSubmit: (value) {
                nick = value;
              },
            ),
            Container(
                margin: EdgeInsets.only(top: 15.h),
                child: Text.rich(TextSpan(style: TextStyle(fontSize: 13.sp, color: const Color(0xFF999999)), children: [
                  TextSpan(text: widget.nickname.btns?.click?.params?.value?.desc ?? '本月剩余修改次数：'),
                  // const TextSpan(text: '12', style: TextStyle(color: Color(0xFFF74437))),
                ]))),
            Container(
                margin: EdgeInsets.only(top: 15.h),
                child: Text.rich(TextSpan(style: TextStyle(fontSize: 13.sp, color: const Color(0xFF000000)), children: [
                  TextSpan(
                      text: widget.nickname.btns?.title ?? '会员用户每月可修改昵称5次，',
                      recognizer: TapGestureRecognizer()..onTap = () {}),
                  // TextSpan(
                  //     text: '点我去开通 >',
                  //     style: const TextStyle(color: Color(0xFF25D4D0)),
                  //     recognizer: TapGestureRecognizer()..onTap = () {}),
                ]))),
          ],
        ),
      ),
    );
  }
}
